<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/base.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/info-mgt.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/WdatePicker.css" />
<link rel="stylesheet" href="__TMPL__Public/assets/layui/css/layui.css">
<link rel="stylesheet" href="__TMPL__Public/assets/book_static/css/pager.css">
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/layui/layui.js"></script>
<title>图书库存管理系统</title>
</head>

<body>
<div class="title"><h2>信息维护</h2></div>
<div class="query">
	<form target="_self" action="" method="GET" id= "dosearch">
		<input type="hidden" name="m" value="index">
		<input type="hidden" name="a" value="list_book">
		<div class="query-conditions ue-clear">
			<div class="conditions staff ue-clear">
				<label>ISBN号：</label>
				<input type="text" name="isbn" id="isbn" placeholder="直接输入ISBN编号进行查询" value="{$data.searchisbn}" />
			</div>
			
			<div class="conditions staff ue-clear">
				<label>书&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</label>
				<input type="text"  name="bookname" id="bookname"  placeholder="可以直接输入书名进行查询"  value="{$data.searchbookname}">
			</div>
		   
		</div>
		<div class="query-btn ue-clear">
			<a href="javascript:$('#dosearch').submit();" class="confirm">查询</a>
			<a href="javascript:$('#isbn').val('');" class="clear">清空条件</a> 
			<div class="layui-upload" style="margin-left: 200px;display: inline;">
			  <button type="button" class="layui-btn layui-btn-normal" id="test8"><i class="layui-icon">&#xe67c;</i>选择文件</button>
			  <button type="button" class="layui-btn" id="test9">上传并导入ISBN信息</button>
			  <a href="/data/shuhao.xls" style="float:right;margin-right:20px;">
				<button type="button" class="layui-btn layui-btn-danger" id="test7"><i class="layui-icon">&#xe61e;</i>下载ISBN信息模板</button>
			  </a>
			</div>
		</div>
		
		
		
			
	</form>
	
</div>


<div class="table-box">
	<table>
    	<thead>
        	<tr>
            	<th class="num">序号</th>
                <th class="name">ISBN</th>
                <th class="node">书名</th>
				<th class="process">位置</th>
                <th class="name">数量<span>(本)</span></th>
                <th class="time">价格</th>
                <th class="time">入库时间</th>
                <th class="operate">操作</th>
            </tr>
        </thead>
        <tbody>
			<foreach name="data.list" item="vo" key="k">
        	<tr class="{$vo.id}">
            	<td class="num">{$vo.id}</td>
                <td class="name isbn" vi="{$vo.bookname}">{$vo.isbn}</td>
                <td class="node bookname" style="width:300px">
				<if condition="$vo.bookname neq ''">
					<!--
					<if condition="$vo.image neq ''">
						<img src="{$vo.image}" width="50" style="padding:8px;"> 
					</if>
					-->
				{$vo.bookname}
				<else/>
				--
				</if>
				</td>
                <td class="process">{$vo.location}</td>
                <td class="name">{$vo.booknum}</td>
                <td class="time price">{$vo.price}</td>
                <td class="time">{$vo.addtime}</td>
                <td class="operate">
				<a href="javascript:void(0);delsure('{$vo.id}')">删除</a> 
				| 
				<!--<a href="javascript:void(0);chuku_one('{$vo.id}')">单本出库</a>
				| -->
				<a href="{:U('index/edite_book')}&bookid={$vo.id}">编辑</a>
				
				</td>
            </tr>
			</foreach>
        </tbody>
    </table>
</div>

<div class="pxofy">当前显示第&nbsp;{$data.page}&nbsp;页，共&nbsp;{$data.total}&nbsp;页&nbsp合计&nbsp;{$data.count}&nbsp;条数据 前往
<select name="pageselect" id="pageselect" style="padding:4px;">
<?php
for($i=1;$i<=$data["total"];$i++){
	$selectedstr = '';
	if($data["page"]==$i){
		$selectedstr = "selected";
	}else{
		$selectedstr = "";
	}
	echo "<option value='".$i."'".$selectedstr.">第".$i."页</option>";
}
?>
</select>
</div>
<div class="page-control ue-clear"></div>


</body>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.page.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/common.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/WdatePicker.js"></script>
<script type="text/javascript" src="__TMPL__Public/assets/book_static/js/jquery.pagination.js"></script>

<script type="text/javascript">
$(".select-title").on("click",function(){
	$(".select-list").hide();
	$(this).siblings($(".select-list")).show();
	return false;
})
$(".select-list").on("click","li",function(){
	var txt = $(this).text();
	$(this).parent($(".select-list")).siblings($(".select-title")).find("span").text(txt);
})

// 分页器
$(".page-control").createPage({
	pageCount:{$data.total},  //总页数
	current:{$data.page},     //当前页数
	callbackFn:function(page){
		var index = layer.load(0, {shade: 0.1}); //0代表加载的风格，支持0-2
		var pageurl = '{$data.pageurl}';
		window.location.href=pageurl+"&page="+page; 
	}
});

//select 分页器
$("#pageselect").change(function(){
	var index = layer.load(0, {shade: 0.1}); //0代表加载的风格，支持0-2
	var pageurl = '{$data.pageurl}';
	var page = $(this).val();
	window.location.href=pageurl+"&page="+page; 
})

$("tbody").find("tr:odd").css("backgroundColor","#eff6fa");

layui.use('upload', function(){
	var $ = layui.jquery
	,upload = layui.upload;
	upload.render({
		elem: '#test8'
		,url: "{:U('index/upisbn')}"
		,accept: 'file'
		,auto: false
		//,multiple: true
		,bindAction: '#test9'
		,before: function(res){
			layer.load(3); //上传loading
		}
		,done: function(res){
			if(res.state=="fail"){
				layer.closeAll('loading');
				layer.msg('导入失败，'+res.message, {time: 5000, icon:5,shade: 0.7});
			}else{
				layer.closeAll('loading');
				layer.msg('导入成功！', {time: 5000, icon:6,shade: 0.7});
				window.location.reload();
			}
		},error: function(index, upload){
			layer.closeAll('loading');
		}
	});
});

function getIsbn(isbn,that){
	var url = "{:U('index/updateisbninfo')}&isbn="+isbn;
	$.getJSON(url,function(result){
		if(result.status==0){
			return false;
		}else{
			var imgstr = '<img src="'+result.image+'" width="50" style="padding:8px;">'+result.title;
			if(typeof(result.title)!="undefined"){
				$(that).closest('tr').find("td.bookname").html(imgstr);
				$(that).closest('tr').find("td.price").html(result.price);
			}else{
				$(that).closest('tr').find("td.bookname").html("系统未获取到该书数据");
			}
		}
	});
}

$(document).ready(function(){
	var updatetime = 0;
	$(".isbn").each(function(i){
		var isbn = $(this).html();
		var bookname = $(this).attr("vi");
		if(isbn==''){
			return true;
		}
		if(bookname!=''){
			return true;
		}
		//getIsbn(isbn,this);
	})
});

function delsure(kucunid){
	if(kucunid==""){
		layer.msg('参数错误！', {icon: 2});return;
	}
	layer.confirm('是否确认删除该信息？', {
		icon: 3,
		btn: ['确认','取消'] //按钮
	}, function(){
		var url = "{:U('index/delbook')}&kucunid="+kucunid;
		window.location.href=url;
	});
}

function chuku_one(bookid){
	if(bookid==""){
		layer.msg('参数错误！', {icon: 2});return;
	}
	layer.confirm('是否确认出库1本该书？', {
		icon: 3,
		btn: ['确认','取消'] //按钮
	}, function(){
		var url = "{:U('index/chuku_one')}&bookid="+bookid;
		window.location.href=url;
	});
}

</script>
</html>
